<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-form-item prop="type"  label="鉴定类型" class="appraisal-list">
        <el-select v-model="dataForm.type" placeholder="请选择" class="appraisal-list">
          <el-option :value="0" label="保管期限期限">保管期限期限</el-option>
          <el-option :value="1" label="密级鉴定">密级鉴定</el-option>
          <el-option :value="2" label="公开鉴定">公开鉴定</el-option>
        </el-select>
      </el-form-item>

      <el-form-item prop="remark" label="备注">
        <el-input type="textarea" :rows="4" placeholder="请输入内容" v-model="dataForm.remark"> </el-input>
      </el-form-item>
      <el-row>
        <el-col :span="24">
          <p>档案列表</p>
          <el-table   style="width: 100%; margin-bottom: 10px">
            <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
            <el-table-column label="序号" prop="code" sortable="custom" header-align="center" align="center"></el-table-column>
            <el-table-column label="档号" prop="fileNumber" header-align="center" align="center"></el-table-column>
            <el-table-column label="题名" prop="title" header-align="center" align="center"></el-table-column>
            <el-table-column label="档号类型" prop="categoryName" header-align="center" align="center"></el-table-column>
            <el-table-column label="密级" prop="createDate" header-align="center" align="center" width="180"></el-table-column>

          </el-table>

          <el-form-item prop="name" label="上传鉴定材料">
            <el-upload class="upload-demo" action="https://jsonplaceholder.typicode.com/posts/" :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" multiple :on-exceed="handleExceed" >
              <el-button size="small" type="primary">点击上传</el-button>
              <template #tip>
                <div class="el-upload__tip">只能上传 jpg/png 文件，且不超过 500kb</div>
              </template>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t("confirm") }}</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts">
import { defineComponent, reactive } from "vue";
import baseService from "@/service/baseService";
import { useDebounce } from "@/utils/utils";
import { IObject } from "@/types/interface";
export default defineComponent({
  setup() {
    return reactive({
      visible: false,
      tenantList: [] as IObject[],
      dataForm: {
        id: "",
        remark: "",
        useWay: "",
        tenantCode: "",
        userPurpose:"",
        type:""
      }
    });
  },
  computed: {
    dataRule() {
      return {
        type: [{ required: true, message: this.$t("validate.required"), trigger: "blur" }]
      };
    }
  },
  created() {
    this.dataFormSubmitHandle = useDebounce(this.dataFormSubmitHandle);
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataFormRef"].resetFields();
      });
    },
    dataFormSubmitHandle() {
      this.$refs["dataFormRef"].validate((valid: boolean) => {
        if (!valid) {
          return false;
        }
        (!this.dataForm.id ? baseService.post : baseService.put)("/archive/appraisal", {
          ...this.dataForm
        }).then((res) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message({
            message: this.$t("prompt.success"),
            type: "success",
            duration: 500,
            onClose: () => {
              this.visible = false;
              this.$emit("refreshDataList");
            }
          });
        });
      });
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    }
  }
});
</script>

<style lang="less" scoped>
  .el-select {
    width: 100%;
  }
</style>
